#include "Convert.hpp"

namespace sl
{
	bool Default(bool var, bool opt)
	{
		if (!var)
			return opt;

		return var;
	}

	double Default(double var, double opt)
	{
		if (var == 0.0)
			return opt;

		return var;
	}

	float Default(float var, float opt)
	{
		if (var == 0.f)
			return opt;

		return var;
	}

	int Default(int var, int opt)
	{
		if (var == 0)
			return opt;

		return var;
	}

	std::string Default(const std::string& var, const std::string& opt)
	{
		if (var == "")
			return opt;

		return var;
	}

	std::string GetNameFromFilename(const std::string& filename)
	{
		char a = filename.find_last_of("/\\") + 1;
		char b = filename.find_last_of(".");
		return filename.substr(a, b - a);
	}

	unsigned int ConvertHex(const std::string& hex)
	{
		std::stringstream ss;
		ss << std::hex << hex;
		unsigned int i;
		ss >> i;
		return i;
	}

	std::string ConvertToHex(unsigned int hex)
	{
		std::stringstream ss;
		ss << "0x" << std::hex << hex;
		std::string s;
		ss >> s;
		return s;
	}
}